<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="epis.unsa.Alumno" %>
<%@ page import="epis.unsa.PMF" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registro de Participaciones en Topocoder</title>
</head>
<body>
<h1>Registro de Parcipaciones en Topcoder</h1>
<%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
    	PersistenceManager pm = PMF.get().getPersistenceManager();
        String query = "select from " + Alumno.class.getName() + 
        				" where email == '" + user + "'";
        List<Alumno> students = (List<Alumno>) pm.newQuery(query).execute();
        if(students.isEmpty()) {
%>
<p>Hola, <%= user.getNickname() %> bienvenido llene el formulario y luego presione siguiente.
<form action="ada" method="post">
	<div> CUI: <input type="text" name="cui"> </div>
	<div> Nombres: <input type="text" name="firstname"> </div>
	<div> Apellidos: <input type="text" name="lastname"> </div>
	<div> handle: <input type="text" name="handle"> </div>
	<div><input type="submit" value="Siguiente" /></div>
</form>


<hr>
(<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">Salir del sistema</a>)</p>

<%
        } else {
        	Alumno student = students.get(0);
%>
<p> Su usuario fué registrado con éxito.
<table border='1'>
	<tr> <td> CUI </td> <td><%=student.getCui()%></td> </tr>
	<tr> <td> Nombres </td> <td><%=student.getFirstname()%></td> </tr>
	<tr> <td> Apellidos </td> <td><%=student.getLastname()%></td> </tr>
	<tr> <td> Handle </td> <td><%=student.getHandle()%></td> </tr>
</table>

<%
        }
    } else {
%>
<p>Ingrese al sistema con su cuenta de
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">gmail</a>.</p>
<%
    }
%>

</body>
</html>